package controller;

import entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;

@Controller
@RequestMapping("/application")
public class ServletContextController {

    //错
    @RequestMapping("/f1")
    public String f1(ServletContext application){
        System.out.println("ServletContextController.f1");
        User user=new User();
        user.setUsername("aaa");
        application.setAttribute("user",user);
        return "application";
    }


    @RequestMapping("/f2")
    public String f2(HttpServletRequest request){
        System.out.println("ServletContextController.f2");
        ServletContext application=request.getServletContext();
        User user=new User();
        user.setUsername("aaa");
        application.setAttribute("user",user);
        return "application";
    }


    @RequestMapping("/f3")
    public String f3(HttpSession session){
        System.out.println("ServletContextController.f3");
        ServletContext application=session.getServletContext();
        User user=new User();
        user.setUsername("aaa");
        application.setAttribute("user",user);
        return "application";
    }

    //错
    @RequestMapping("/f4")
    public String f4(PageContext pageContext){
        System.out.println("ServletContextController.f4");
        ServletContext application=pageContext.getServletContext();
        User user=new User();
        user.setUsername("aaa");
        application.setAttribute("user",user);
        return "application";
    }

    //错
    @RequestMapping("/f5")
    public String f5(ServletConfig servletConfig){
        System.out.println("ServletContextController.f5");
        ServletContext application=servletConfig.getServletContext();
        User user=new User();
        user.setUsername("aaa");
        application.setAttribute("user",user);
        return "application";
    }
}
